package gk.example.activity;

import gk.example.BaseActivity;
import gk.example.adapter.OtherInfoAdapter;
import gk.example.bean.User;
import gk.example.util.ErrorCodeUtil;
import gk.example.util.ImageLoadUtil;
import gk.example.view.ProgressDialog;

import java.util.List;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.listener.FindListener;

import com.example.gkdate.R;

import de.hdodenhof.circleimageview.CircleImageView;

public class OtherInfoActivity extends BaseActivity implements OnClickListener {
	private TextView mTvTitle;
	private ImageButton mBtnBack;
	private CircleImageView mImageHead;
	private ListView mLvInfo;
	private ProgressDialog mProgressDialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

	}

	@Override
	protected void initView() {
		setContentView(R.layout.activity_other_info);
		mImageHead = (CircleImageView) findViewById(R.id.iv_other_info_head);
		mLvInfo = (ListView) findViewById(R.id.lv_other_info);
		mBtnBack = (ImageButton) findViewById(R.id.btn_back);
		mTvTitle = (TextView) findViewById(R.id.tv_top_title);
		mProgressDialog = new ProgressDialog();
	}

	@Override
	protected void initEvent() {
		mTvTitle.setText("信息");
		mBtnBack.setOnClickListener(this);
		mProgressDialog.show(getSupportFragmentManager(), "Loading");
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		String UserID = bundle.getString("userid");
		BmobQuery<User> query = new BmobQuery<User>();
		query.addWhereMatches("objectId", UserID);
		query.findObjects(this, new FindListener<User>() {

			@Override
			public void onSuccess(List<User> arg0) {
				ImageLoadUtil.getInstance().setImageBackground(
						OtherInfoActivity.this,
						false,
						mImageHead,
						arg0.get(0).getUserHead()
								.getFileUrl(OtherInfoActivity.this), null, 64,
						64);
				mImageHead.setVisibility(View.VISIBLE);
				mLvInfo.setAdapter(new OtherInfoAdapter(OtherInfoActivity.this,
						arg0.get(0)));
				mProgressDialog.dismiss();
			}

			@Override
			public void onError(int arg0, String arg1) {
				ErrorCodeUtil.Errorshow(OtherInfoActivity.this, arg0, "加载失败");
				mProgressDialog.dismiss();
			}
		});
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		default:
			break;
		}

	}

}
